# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: helpers\cleanup\base.py
__author__ = "Attila Gerendi (Sanyi)"
import datetime
from dateutil.tz import tzutc
import logging

_logger = logging.getLogger("helpers.cleanup.base")


class Cleanup:
    def __init__(self, recurrence):
        self.should_stop = False
        self.recurrence = recurrence
        self.last_run = None

    def run_once_internal(self):
        raise NotImplementedError()

    def stop(self):
        self.should_stop = True

    def run_once(self):
        if (
            self.last_run is None
            or self.last_run + self.recurrence < datetime.datetime.now(tzutc())
        ):
            pass
        try:
            self.run_once_internal()
        except Exception as e:
            _logger.exception("cleanup process failed with %s", e)
